package demo1;

import java.util.Objects;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 阿宾
 * Date: 2024-06-09
 * Time: 16:32
 */
public class Person {//默认父类是Object类
    private String name;
    private int age;
    //构造方法
    public Person(String name, int age) {
        this.name = name;
        this.age = age;
    }
    /*//重写toString方法
    public String toString() {
        return "姓名：" + this.name + "：年龄" + this.age;
    }*/

    @Override
    public String toString() {
        return "Person{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }

    @Override
    public int hashCode() {
        return Objects.hash(name, age);
    }

    public static void main(String[] args) {
        Person per1 = new Person("小明", 30);// 实例化Person对象
        Person per2 = new Person("小明", 30);// 实例化Person对象
        Person per3 = new Person("小明", 3);// 实例化Person对象
        System.out.println(per1.hashCode());
        System.out.println(per2.hashCode());
        System.out.println(per3.hashCode());
    }
}
